package com.yanqu.road.server.logic.recharge;

import com.mysql.jdbc.log.Log;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.log.LogActivityFestivalGiftBuy;
import com.yanqu.road.entity.recharge.RechargeOrder;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityMallModule;
import com.yanqu.road.server.gameplayer.module.activity.festivalgift.FestivalGiftModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.log.LogMgr;
import com.yanqu.road.server.manger.maidian.DefaultEventTraceAction;
import com.yanqu.road.server.manger.maidian.festivalgift.FestivalGiftLog;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;

public class FestivalGiftMallRecharge extends BaseRecharge {

    public FestivalGiftMallRecharge(GamePlayer player, MallInfo mallInfo, ActivityInfo activityInfo) {
        super(player, mallInfo, activityInfo);
    }

    @Override
    protected boolean isRepeatedBuy(String orderNo) {
        return player.getModule(ActivityMallModule.class).isOverLimitBuyCount(mallInfo, 1);
    }

    @Override
    protected void repeatedBuyLogic() {

    }

    @Override
    protected String addMall(String orderNo, RechargeOrder rechargeOrder) {
        //获取自选道具
        String selectRewardStr = player.getModule(FestivalGiftModule.class).successBuy(mallInfo.getActivityId(), mallInfo.getMallId());
        //自身的道具
        Property property = new Property();
        Property gdProperty = PropertyHelper.parseStringToProperty(mallInfo.getReward());
        property.addProperty(gdProperty);
        if (!StringUtils.isNullOrEmpty(selectRewardStr)) {
            property.addProperty(PropertyHelper.parseStringToProperty(selectRewardStr));
        }
        player.getModule(CurrencyModule.class).addCurrency(property, eLogMoneyType.Recharge, eLogMoneyType.ReChargeGet);
        logger.info("订单: {}, 直购现金礼包购买 自选礼包 商品: {}", orderNo, mallInfo.getMallId());
        //添加日志
        LogActivityFestivalGiftBuy log = new LogActivityFestivalGiftBuy();
        log.setActivityId(activityInfo.getActivityId());
        log.setMallId(mallInfo.getMallId());
        log.setUserId(player.getUserId());
        log.setSelectProp(selectRewardStr);
        log.setFixedProp(mallInfo.getReward());
        log.setCreateTime(System.currentTimeMillis());
        LogMgr.addLogActivityFestivalGiftBuy(log);
        //数数日志
        FestivalGiftLog.trackFestivalGift(player, activityInfo.getActivityId(), mallInfo.getMallId(), selectRewardStr, mallInfo.getReward());
        return PropertyHelper.parsePropertyToString(property);
    }
}
